package com.sduept.nwld.dataserver.controller.riskalarm;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;

import org.springframework.beans.factory.annotation.Autowired;

import com.sduept.bigdata.document.entity.core.RecordAttachment;
import com.sduept.bigdata.document.services.RecordAttachmentManager;
import com.sduept.bigdata.fault.protection.model.ProtectDeviceAlarm;
import com.sduept.bigdata.fault.protection.service.ProtectDeviceAlarmQueryManager;
import com.sduept.bigdata.web.jsf.controller.AbstractController;
import com.sduept.message.entity.AlarmMessageCheck;
import com.sduept.message.manager.AlarmMessageCheckManager;
import com.sduept.utils.DateUtil;

@Named
@ViewScoped
public class ProtectDeviceException extends AbstractController{
     
	@Autowired
	private ProtectDeviceAlarmQueryManager pd;
	@Autowired
	private AlarmMessageCheckManager amc;
	@Autowired
	private RecordAttachmentManager ram;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
    private List<ProtectDeviceAlarm> protectDeviceList=null;
    private AlarmMessageCheck check=null;
    private List<RecordAttachment> attachments = new ArrayList<>();
    
    @PostConstruct
	private void init() {
    	String oId=getParameter("oId");
    	String msgId=getParameter("msgId");
    	List<ProtectDeviceAlarm> protectDeviceList1=pd.getProtectDeviceAlarmById(oId);
    	check=amc.getAlarmMessageCheckByMsgId(msgId);
    	if(protectDeviceList1.size()>0){
    		ProtectDeviceAlarm pa = protectDeviceList1.get(0);
    		Date start = pa.getEventStart();
    		Date end = new Date(pa.getEventStart().getTime()+86400000);
    		protectDeviceList=pd.getProtectDeviceAlarmByDate(DateUtil.getStringDate(start, DateUtil.pattern_ymdhms), DateUtil.getStringDate(end, DateUtil.pattern_ymdhms));
    	}
    	if(null==check) {
			check=new AlarmMessageCheck();
		}
    	attachments = ram.getAttachmentsByOId(check.getId());
    }

	public List<ProtectDeviceAlarm> getProtectDeviceList() {
		return protectDeviceList;
	}

	public void setProtectDeviceList(List<ProtectDeviceAlarm> protectDeviceList) {
		this.protectDeviceList = protectDeviceList;
	}

	public AlarmMessageCheck getCheck() {
		return check;
	}

	public void setCheck(AlarmMessageCheck check) {
		this.check = check;
	}

	public List<RecordAttachment> getAttachments() {
		return attachments;
	}

	public void setAttachments(List<RecordAttachment> attachments) {
		this.attachments = attachments;
	}



}
